<template>
	<view class="content">
		<view class="top-advert">
			<image class="img" src="http://eatbeancar-file-services.oss-cn-hangzhou.aliyuncs.com/eatbeancar-life/image/20200413/db89599765bf4f35b71b4b53e527a3fb.jpg"></image>
		</view>
		<view class="item-layout">
			<view v-for="item of items" :key='item.id' class="view-layout" @click="clickItem(item.id)">
				<image :src="item.img" class="item-img" />
				<text class="item-txt">{{item.name}}</text>
			</view>
		</view>
		<view v-for="item of types" :key='item.id'>
			<text class="text-type">{{item.catalog}}</text>
		</view>
		<view class="hotString">{{hotString}}</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				items: [{
						'id': '1',
						'name': '笑话大全',
						'img': '../../static/index_gw.png'
					},
					{
						'id': '2',
						'name': '今日油价',
						'img': '../../static/index_lp.png'
					},
					{
						'id': '3',
						'name': '功能3',
						'img': '../../static/index_red.png'
					},
					{
						'id': '4',
						'name': '功能4',
						'img': '../../static/index_vip.png'
					},
					{
						'id': '5',
						'name': '新闻头条',
						'img': '../../static/index_xz.png'
					}
				],
				types: [],
				hotString: ""
			}
		},
		onLoad() {
			this.loadBooksType()
			this.loadHotString()
		},
		methods: {
			clickItem(idStr) {
				console.log("idStr:" + idStr)
				if (idStr == 1) {
					uni.navigateTo({
						url: "../joke/joke"
					})
				} else if (idStr == 2) {
					uni.navigateTo({
						url: "../oilPrice/oilPrice"
					})
				} else if (idStr == 5) {
					uni.navigateTo({
						url: "../news/news"
					})
				}
			},
			loadBooksType() {
				var weakThis = this
				uni.request({
					url: '/goodbook/catalog?key=a1ef4694abd3daa039a023ab865baf1f',
					data: {},
					method: 'GET',
					success(res) {
						console.log(res.data.result)
						if (res.data.error_code == 0) {
							weakThis.types = res.data.result
							weakThis.loadBooksList(weakThis.types[0].id)
						}
					}
				})
			},
			loadBooksList(typeId) {
				var weakThis = this
				uni.request({
					url: '/goodbook/query?key=a1ef4694abd3daa039a023ab865baf1f&catalog_id=' + typeId +
						'&pn=1&rn=10',
					data: {},
					method: 'GET',
					success(res) {
						console.log(res.data.result)
						if (res.data.error_code == 0) {}
					}
				})
			},
			loadHotString(typeId) {
				var weakThis = this
				uni.request({
					url: 'https://api.66mz8.com/api/social.php?format=json',
					method: 'GET',
					success(res) {
						if (res.data.code == 200) {
							weakThis.hotString = res.data.social
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.content {
		width: 100%;
		background-color: #F2F2F2;
	}

	.top-advert {
		height: 300rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;

		.img {
			height: 100%;
			width: 100%;
		}
	}

	.item-layout {
		flex-direction: row;
		display: flex;

		.view-layout {
			display: flex;
			flex-direction: column;
			flex: 1;
			justify-content: center;
			align-items: center;
			padding-top: 20rpx;
			padding-bottom: 20rpx;

			.item-img {
				width: 60rpx;
				height: 60rpx;
			}

			.item-txt {
				margin-top: 10rpx;
				font-size: 20rpx;
				color: #1b1b1b;
			}
		}
	}

	.hotString {
		background-color: #FFFFFF;
		padding: 20rpx;
		font-size: 26rpx;
		color: #DD524D;
	}

	.table-layout {
		background-color: #4CD964;
		height: 300rpx;
		width: 100%;
	}

	.text-type {
		color: red;
		height: 50rpx;
		width: 100%;
	}
</style>
